<?php

include("../../config.php");

if(isset($_POST['login'])) {
    include_once(DAO."/AdminDAO.php");
    $admin = new AdminDAO;
    $login = $admin->login($_POST['login'],$_POST['senha']);
    if($login) die("ok");
    else die("Erro!");
}


?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <script src="<?=URL;?>/gui/js/jquery-1.3.2.min.js" type="text/javascript"></script>
        <link href="<?=URL;?>/gui/css/style.css" rel="stylesheet" type="text/css" />
        <title>:: ComprasWeb ::</title>
        <script type="text/javascript">
            $(document).ready(function(){
                $("form").bind('submit', function(event){
                    event.preventDefault(); // Cancela o envio do form
                    var l = $("#login").val();
                    var s = $("#senha").val();
                    $.ajax({
                        type: "POST",
                        url: "login.php",
                        data: {
                            login:l,
                            senha:s
                        },
                        dataType: "text",
                        success: function(data) {
                            if(data == "ok"){
                                // login ok
                                //alert('vai redirecionar');
                                window.parent.location.href='../../admin.php';
                            } else {
                                alert("login e/ou senha incorreta!\n"+data);
                            }
                        }
                    });
                });
            });
        </script>
    </head>
    <body>
        <div>
            <form>
                <table id="table-login">
                    <tr>
                        <td>Login:</td>
                        <td><input name="login" id="login" /></td>
                    </tr>
                    <tr>
                        <td>Senha:</td>
                        <td><input name="senha" id="senha" type="password" /></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="ok" value="Entrar" /></td>
                    </tr>
                </table>
            </form>
        </div>
    </body>
</html>